package com.example.quart.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/11/1 14:48
 */
@Slf4j(topic = "dateTimeJob")
public class DateTimeJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            //获取JobDetail中关联的数据
            String msg = (String) context.getJobDetail().getJobDataMap().get("msg");
            log.info("current time -- :{} --- {}",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),msg);
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.error("executeInternal error {}",e.getMessage(),e);
        }
    }
}
